#pragma once
#include "Mesh.h"
class Shirt
{
public:
	Mesh * front;
	Mesh * back;
	Points linkpoints;
	int t;
	Shirt(void);
	Shirt(char* filenamefront, char* filenameback);
	~Shirt(void);
	void timeStep();
	void addForce(const Vec3 direction);
	void windForce(const Vec3 direction);
	void ballCollision(const Vec3 center,const float radius );
	void addWindForcesForTriangle(Particle *p1,Particle *p2,Particle *p3, const Vec3 direction);
	void drawShaded();
	//void Connect(Mesh *front,Mesh *back, int i1,int i2);
	Particle* p1;
	Particle* p2;
	float x,y,z;
};
void Shirt::drawShaded()
{
	front->drawShaded();
	back->drawShaded();
}
void Shirt::timeStep()
{
	front->timeStep();
	back->timeStep();
	for(t=0;t<linkpoints.n;t++)
	{
		//if(front->valued_point[linkpoints.p[t].x][linkpoints.p[t].y])
		{
		p1 = front->getParticle(linkpoints.p[t].x,linkpoints.p[t].y);
		p2 = back->getParticle(linkpoints.p[t].x,linkpoints.p[t].y);
		x = (p1->pos.f[0] + p2->pos.f[0])/2;
		y = (p1->pos.f[1] + p2->pos.f[1])/2;
		z = (p1->pos.f[2] + p2->pos.f[2])/2;
		p1->pos.f[0] = p2->pos.f[0] = x;
		p1->pos.f[1] = p2->pos.f[1] = y;
		p1->pos.f[2] = p2->pos.f[2] = z;
		}
	}
	
}
void Shirt::addForce(const Vec3 direction)
{
	front->addForce(direction);
	back->addForce(direction);
}
void Shirt::windForce(const Vec3 direction)
{
	//front->windForce(direction);
	//back->windForce(direction);
}
void Shirt::ballCollision(const Vec3 center,const float radius )
{
	front->ballCollision(center,radius);
	back->ballCollision(center,radius);
}
void Shirt::addWindForcesForTriangle(Particle *p1,Particle *p2,Particle *p3, const Vec3 direction)
{
	//front->addWindForcesForTriangle(p1,p2,p3,direction);
	//back->addWindForcesForTriangle(p1,p2,p3,direction);
}
Shirt::Shirt(char* filenamefront, char* filenameback)
{
	front = new Mesh(filenamefront,4);
	back = new Mesh(filenameback,-4);
	int linelist[] = {1,2,4,5,7,8,10,11};
	for(int i=0;i<8;i++)
	{
		for(int j =0;j< front->point_list[i].n;j++)
		{
			//cout << front->point_list[i].p[j].x << " " << front->point_list[i].p[j].y << endl;
			linkpoints.Add(front->point_list[i].p[j].x,front->point_list[i].p[j].y);
		}
	}

}
Shirt::Shirt(void)
{

}

Shirt::~Shirt(void)
{
}
